# reset prefix, C-b is used by vim
set-option -g prefix C-s
bind-key C-s last-window

#- # https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set -ga terminal-overrides ",xterm-256color:Tc"

# set copy-mode
bind Escape copy-mode
bind Enter copy-mode

# synchronize panes
bind S set synchronize-panes on
bind A set synchronize-panes off

# clear history
bind y clear-history

# reload config
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."

# panes
bind v split-window -h
bind s split-window
bind c new-window -c "#{pane_current_path}"
bind C command-prompt -p "Name of new window: " "new-window -n '%%'"
bind b choose-tree -Zs
bind H swap-pane -U
bind L swap-pane -D

# pane switching with awareness of vim splits
# bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)n?vim(diff)?$|emacs.*$' && tmux send-keys C-h) || tmux select-pane -L"
# bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)n?vim(diff)?$|emacs.*$' && tmux send-keys C-j) || tmux select-pane -D"
# bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)n?vim(diff)?$|emacs.*$' && tmux send-keys C-k) || tmux select-pane -U"
# bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)n?vim(diff)?$|emacs.*$' && tmux send-keys C-l) || tmux select-pane -R"
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# pane resizing
bind -r C-h resize-pane -L 5
bind -r C-j resize-pane -D 5
bind -r C-k resize-pane -U 5
bind -r C-l resize-pane -R 5
bind C-z resize-pane -Z

# Start numbering at 1
set -g base-index 1

# Allows for faster key repetition
set -s escape-time 10

# Allows us to use C-a a <command> to send commands to a TMUX session inside
# another TMUX session
bind a send-prefix

# Activity monitoring
setw -g monitor-activity on
set -g visual-activity on

# Vi copypaste mode
setw -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-selection
bind -T copy-mode-vi r send-keys -X rectangle-toggle

# set to main-horizontal, 60% height for main pane
bind m set-window-option main-pane-height 60\; select-layout main-horizontal

# auto window rename
setw -g automatic-rename

# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse on

# Style config
#  modes
setw -g mode-style fg=colour9,bg=colour238

# panes
set -g pane-active-border-style fg=blue
set -g pane-border-style fg=colour145

# statusbar
set -g status-interval 1
set -g status-justify centre # center align window list
set -g status-position bottom
set -g status-style fg=default,bg=default
# install tmux-mem-cpu-load first: brew install tmux-mem-cpu-load
set -g status-left '#[fg=yellow]%Y-%m-%d #[fg=white,bright]%a%l:%M:%S %p#[default]'
set -g status-right '#[fg=colour42,bright]#(tmux-mem-cpu-load --interval 2)#[default]'
set -g status-left-length 40
set -g status-right-length 80

# current window
setw -g window-status-current-style fg=colour44,bold
setw -g window-status-current-format '#I:#W#F'

# window
setw -g window-status-style fg=colour247
setw -g window-status-format '#I:#W#F'

# set -g window-status-format "#[fg=colour254,bold,noreverse] #I:#W#F "
# set -g window-status-current-format "#[fg=colour234,bg=colour39]#[fg=white,bg=colour68,noreverse,bold] #I:#T#F #[fg=colour39,bg=colour234,nobold]"
# set -g window-status-format '#I:#W[#(pwd="#{pane_current_path}"; echo ${pwd####*/})]#F'
# set -g window-status-current-format '#I:#W[#(pwd="#{pane_current_path}"; echo ${pwd####*/})]#F'
# set -g window-status-format '#I:#W#F'
# set -g window-status-current-format '#I:#W#F'
